<table class="form-table-without-line">
    <tr>
        <th>期号</th>
        <td>
            <input type="text" class="am-form-field issue" placeholder="输入待设置的期数" />
        </td>
    </tr>
    <tr>
        <th>开奖结果</th>
        <td>
            <input type="text" class="am-form-field result" placeholder="5个开奖号码，请用,隔开" />
            <button type="button" class="save">保存</button>
        </td>
    </tr>
</table>

<script src="../public/all/js/result.js"></script>
<script>
    // 将最近一期的期号和开奖时间填入
    var game = 'cqssc';
    Result.switchGame(game);
    Result.cb = function() {
        var curr = Result.curr();
        if (!curr) return;

        $(".issue").val(curr.issue);
    };

    $("button.save").click(function() {
        var arr = $("input.result").val().trim().split(",");
        if (arr.length != 5) {
            alert2("开奖号码应该为5个！", true);
            return;
        }

        for (var i = 0; i < arr.length; i++) {
            var n = arr[i];
            if (n == '' || parseInt(n) < 0 || parseInt(n) > 9) {
                alert2("开奖结果数字应该为0-9。", true)
                return;
            }
            n = parseInt(n);
            arr[i] = n;
        } 

        // 保存
        startLoading();
        CMD.set_lottery_result(game, $(".issue").val().trim(), arr, function() {
            stopLoading();
            alert2("设置成功！");
        });
    });
</script>
